home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
FinderGrok
/
osa stuff
/
CCWDisplayLine.cp
< prev
next >
Wrap
Text File
|
2000-06-23
|
4KB
|
149 lines
// =================================================================================
// CCWDisplayLine.cp ©1996-1999 Metrowerks Inc. All rights reserved.
// =================================================================================
using namespace std;
#include "CCWDisplayLine.h"
#include "MoreOSA.h"
#include "CAEDescriptor.h"
#include "Str255.h"
#include "SelectFile.h"
SelectFile theSelectorStuff;
static Boolean firstTime = true;
bool TestParse(FSSpec *theSpec)
{
return theSelectorStuff.PaternMatch(theSpec->name);
}
#ifdef CONDUIT
#include "CConduitDialog.h"
static pascal Boolean defaultIdleProc(EventRecord *eventRecord, long *sleepTime, RgnHandle *mouseRegion)
{
return CConduitDialog::AEIdleProc(eventRecord, sleepTime, mouseRegion);
}
#else
static pascal Boolean defaultIdleProc(EventRecord *eventRecord, long *sleepTime, RgnHandle *mouseRegion)
{
if (firstTime) {
*sleepTime = 30;
*mouseRegion = 0;
firstTime = 0;
}
LEventDispatcher *eventD = LEventDispatcher::GetCurrentEventDispatcher();
if (eventD != 0) {
eventD->DispatchEvent(*eventRecord);
}
return false;
}
#endif
static AEIdleUPP gDefaultIdleProc = NewAEIdleProc(defaultIdleProc);
Handle CCWDisplayLine::gDisplayScript = 0;
CCWDisplayLine::CCWDisplayLine(const string& fileName, SInt32 lineToDisplay)
: fFileName(fileName), fLineToDisplay(lineToDisplay)
{
}
void
CCWDisplayLine::Display()
{
AEKeyword keyWord;
DescType typeCode;
int theInt;
Size actualSize;
OSErr err;
Rect testRect;
int theLeft, theTop, theRight, theBottom;
theSelectorStuff.Run();
if (gDisplayScript == 0) {
CompileDisplayScript();
}
ScriptObject script;
script.SetIdleProc(gDefaultIdleProc);
script.Load(gDisplayScript);
CAEDescriptor params;
// CAEDescriptor fileNameDesc(AsStr255(fFileName));
CAEDescriptor lineToDisplayDesc(fLineToDisplay);
ThrowIfOSErr_( AECreateList(NULL, 0, false, params) );
// ThrowIfOSErr_( AEPutDesc(params, 1, fileNameDesc) );
ThrowIfOSErr_( AEPutDesc(params, 1, lineToDisplayDesc) );
script.CallSubroutine("displaywindowlocation", params);
CAEDescriptor result;
CAEDescriptor outList;
ThrowIfOSErr_( AECreateList(NULL, 0, false, outList) );
script.ReturnResults(result);
err = AEGetNthPtr(result, 1, typeInteger, &keyWord, &typeCode, &theLeft, sizeof(theInt), &actualSize);
err = AEGetNthPtr(result, 2, typeInteger, &keyWord, &typeCode, &theTop, sizeof(theInt), &actualSize);
err = AEGetNthPtr(result, 3, typeInteger, &keyWord, &typeCode, &theRight, sizeof(theInt), &actualSize);
err = AEGetNthPtr(result, 4, typeInteger, &keyWord, &typeCode, &theBottom, sizeof(theInt), &actualSize);
SetRect(&testRect, theLeft, theTop, theRight, theBottom);
long outCount = 0;
long theCount;
int i;
FSSpec testSpec;
script.CallSubroutine("getfilelist", params);
script.ReturnResults(result);
err = AECountItems(result, &theCount);
for (i = theCount; i >= 1; i--)
{
err = AEGetNthPtr(result, i, typeFSS, &keyWord, &typeCode, &testSpec, sizeof(testSpec), &actualSize);
if (err == noErr)
{
if (TestParse(&testSpec) == false)
{
err = AEDeleteItem(result, i);
// CAEDescriptor newDesc;
// err = AEGetNthDesc(outList, (long) i, /*'docf'*/typeWildCard, &keyWord, newDesc);
// err = AEPutDesc(outList, outCount, newDesc);
}
else
outCount++;
}
}
if (outCount > 0)
{
CAEDescriptor params2;
ThrowIfOSErr_( AECreateList(NULL, 0, false, params2) );
// ThrowIfOSErr_( AEPutDesc(params2, 1, outList) );
ThrowIfOSErr_( AEPutDesc(params2, 1, result) );
ThrowIfOSErr_( AEPutDesc(params2, 2, lineToDisplayDesc) );
script.CallSubroutine("setfilelist", params2);
}
}
ConstStringPtr kScriptFileName = "\pMacintosh HD:GrokScript";
void
CCWDisplayLine::CompileDisplayScript()
{
ScriptObject script;
FSSpec scriptSpec;
ThrowIfOSErr_(::FSMakeFSSpec(0, 0, kScriptFileName, &scriptSpec));
script.Load(&scriptSpec);
gDisplayScript = script.Store((Handle)0);
HandToHand(&gDisplayScript);
}